package com.dtagri.fjwlw.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

/**
 * 重新封装BroadcastReceiver，方便使用
 * 
 * @author wxjn
 * 
 */
public abstract class TReceiver extends BroadcastReceiver {

	// 基地切换
	public static final String CHANG_BASE = "android.intent.action.CHANG_BASE";
	// 设备控制退出
	public static final String CONTROL_BACK = "android.intent.action.CONTROL_BACK";
	
	private Context context;

	public TReceiver(Context context) {
		this.context = context;
	}

	public TReceiver(Context context, String action) {
		this.context = context;
		registerReceiver(action);
	}

	public void registerReceiver(String action) {
		IntentFilter filter = new IntentFilter();
		filter.addAction(action);
		context.registerReceiver(this, filter);
	}

	public void unregisterReceiver() {
		context.unregisterReceiver(this);
	}

	public static void sendBroadCast(Context context, String action) {
		Intent intent = new Intent(action);
		context.sendBroadcast(intent);
	}
}
